<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { useToast } from 'wot-design-uni'
import { useLocationStore } from '@/store/location'
import { http } from '@/utils/http'
import { userApi } from '@/api/api'

// ...其他接口定义保持不变...

const locationStore = useLocationStore()
const toast = useToast()

const formData = reactive<RegisterForm>({
  realname: '',
  address: '',
  avatar: '',
  phone: '',
  latitude: locationStore.selectedLocation?.latitude,
  longitude: locationStore.selectedLocation?.longitude,
})
// 初始化时从store加载地址
if (locationStore.selectedLocation) {
  formData.address = locationStore.selectedLocation.address
}

// 跳转到地图选择页面
const goToLocationPage = () => {
  // 如果有已保存的位置，设置为初始位置
  if (locationStore.selectedLocation) {
    locationStore.setTempLocation(locationStore.selectedLocation)
  }

  uni.navigateTo({
    url: '/pages-user/location/location',
  })
}

// 监听位置变化（可选）
const unsubscribe = locationStore.$subscribe((mutation, state) => {
  if (state.selectedLocation) {
    formData.address = state.selectedLocation.address
    formData.latitude = state.selectedLocation.latitude
    formData.longitude = state.selectedLocation.longitude
  }
})

// 组件卸载时取消订阅
onUnmounted(() => {
  unsubscribe()
})

// ...其他方法保持不变...
</script>
